1874A - Jellyfish and Game - CodeForces Solution


brute force games greedy implementation

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while (t--) {
        int n, m, k;
        cin >> n >> m >> k;
        int min_a = 1e9, max_a = 1, min_b = 1e9, max_b = 1;
        long long int sum_a = 0;
        for (int i=0; i<n; i++) {
            int temp;
            cin >> temp;
            sum_a += temp;
            min_a = min_a < temp ? min_a : temp;
            max_a = max_a > temp ? max_a : temp;
        }
        for (int i=0; i<m; i++) {
            int temp;
            cin >> temp;
            min_b = min_b < temp ? min_b : temp;
            max_b = max_b > temp ? max_b : temp;
        }
        
        if (min_a < max_b) {
            sum_a += - min_a + max_b;
            min_b = min(min_a, min_b);
            max_a = max(max_a, max_b);
        }
        if (k&1) cout << sum_a << "\n";
        else {
            if (min_b < max_a) {
                sum_a += min_b - max_a;
            }
            cout << sum_a << "\n";
        }
    }

    return 0;
}


Comments

Submit
0 Comments
More Questions

1118A - Water Buying
1462C - Unique Number
301A - Yaroslav and Sequence
38A - Army
38C - Blinds
1197A - DIY Wooden Ladder
1717D - Madoka and The Corruption Scheme
1296D - Fight with Monsters
729D - Sea Battle
788A - Functions again
1245B - Restricted RPS
1490D - Permutation Transformation
1087B - Div Times Mod
1213B - Bad Prices
1726B - Mainak and Interesting Sequence
1726D - Edge Split
1726C - Jatayu's Balanced Bracket Sequence
1726A - Mainak and Array
1613C - Poisoned Dagger
475B - Strongly Connected City
652B - z-sort
124B - Permutations
1496C - Diamond Miner
680B - Bear and Finding Criminals
1036E - Covered Points
1015D - Walking Between Houses
155B - Combination
1531A - Зингер | color
1678A - Tokitsukaze and All Zero Sequence
896A - Nephren gives a riddle